//
//  MBProgressHUD+XX.m
//  KaneNote
//
//  Created by HuanJing on 2017/7/13.
//  Copyright © 2017年 HuanJing. All rights reserved.
//

#import "MBProgressHUD+XX.h"

@implementation MBProgressHUD (XX)

/**
 *  快速显示一条信息
 */
+ (void)showXXMessage:(NSString *)message {
    UIView *view = [[UIApplication sharedApplication].windows lastObject];
    [self showXXMessage:message toView:view hideAfterDelay:1.2f];
}

+ (void)showXXMessage:(NSString *)message toView:(UIView *)view hideAfterDelay:(NSTimeInterval)time {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = message;
    hud.margin = 10.f;
    hud.removeFromSuperViewOnHide = YES;
//    [hud hide:YES afterDelay:time];
    [hud hideAnimated:YES afterDelay:time];
}

+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view{
    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    }
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = text;
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD_XX.bundle/%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // 1秒之后再消失
//    [hud hide:YES afterDelay:1];
    [hud hideAnimated:YES afterDelay:1];
}

/**
 *  显示错误(Error)提示
 */
+ (void)showError:(NSString *)error {
    [self show:error icon:@"hud_error.png" view:nil];
}

/**
 *  显示成功(Success)提示
 */
+ (void)showSuccess:(NSString *)success {
    [self show:success icon:@"hud_success.png" view:nil];
}

/**
 *  显示警告(Warning)提示
 */
+ (void)showWarning:(NSString *)warning {
    [self show:warning icon:@"hud_warning.png" view:nil];
}

/**
 *  显示没有数据(NoData)提示
 */
+ (void)showNodata:(NSString *)nodata {
    [self show:nodata icon:@"hud_noData.png" view:nil];
}

@end
